﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Help
{
    public class PublicMethod
    {
        #region 获取当前时间（格式：20131229123412）
        /// <summary>
        /// 获取当前时间（格式：201312291234）
        /// </summary>
        /// <returns></returns>
        public string getDateTimeNow()
        {
            //string dtnow = "";
            //string month = "";
            //string day = "";
            //string hour = "";
            //string minute = "";
            //string second = "";
            //DateTime dt = DateTime.Now;
            //int dd = dt.Month.ToString().Length;
            //if (dt.Month.ToString().Length < 2)
            //    month = "0" + dt.Month.ToString();
            //else
            //    month = dt.Month.ToString() + "";
            //if (dt.Day.ToString().Length < 2)
            //    day = "0" + dt.Day.ToString();
            //else
            //    day = dt.Day.ToString() + "";
            //if (dt.Hour.ToString().Length < 2)
            //    hour = "0" + dt.Hour.ToString();
            //else
            //    hour = dt.Hour.ToString() + "";
            //if (dt.Minute.ToString().Length < 2)
            //    minute = "0" + dt.Minute.ToString();
            //else
            //    minute = dt.Minute.ToString() + "";
            //if (dt.Second.ToString().Length < 2)
            //    second = "0" + dt.Minute.ToString();
            //else
            //    second = dt.Minute.ToString() + "";
            //dtnow = dt.Year.ToString() + month + day + hour + minute + second;
            //return dtnow;
            return DateTime.Now.ToString("yyyyMMddHHmmss");
        }
        #endregion

        #region 在当前时间上增加月
        /// <summary>
        /// 在当前时间上增加月
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public string NewTimeAddMonths(int Months)
        {
            string dtnow = "";
            string month = "";
            string day = "";
            string hour = "";
            string minute = "";
            string second = "";
            DateTime dt = DateTime.Now.AddMonths(Months);
            int dd = dt.Month.ToString().Length;
            if (dt.Month.ToString().Length < 2)
                month = "0" + dt.Month.ToString();
            else
                month = dt.Month.ToString() + "";
            if (dt.Day.ToString().Length < 2)
                day = "0" + dt.Day.ToString();
            else
                day = dt.Day.ToString() + "";
            if (dt.Hour.ToString().Length < 2)
                hour = "0" + dt.Hour.ToString();
            else
                hour = dt.Hour.ToString() + "";
            if (dt.Minute.ToString().Length < 2)
                minute = "0" + dt.Minute.ToString();
            else
                minute = dt.Minute.ToString() + "";
            if (dt.Second.ToString().Length < 2)
                second = "0" + dt.Minute.ToString();
            else
                second = dt.Minute.ToString() + "";
            dtnow = dt.Year.ToString() + month + day + hour + minute + second;
            return dtnow;
        }
        #endregion

        #region 在当前时间上增加月
        /// <summary>
        /// 在当前时间上增加分
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public string NewTimeAddMinutes(int Minutes)
        {
            string dtnow = "";
            string month = "";
            string day = "";
            string hour = "";
            string minute = "";
            string second = "";
            DateTime dt = DateTime.Now.AddMinutes(Minutes);
            int dd = dt.Month.ToString().Length;
            if (dt.Month.ToString().Length < 2)
                month = "0" + dt.Month.ToString();
            else
                month = dt.Month.ToString() + "";
            if (dt.Day.ToString().Length < 2)
                day = "0" + dt.Day.ToString();
            else
                day = dt.Day.ToString() + "";
            if (dt.Hour.ToString().Length < 2)
                hour = "0" + dt.Hour.ToString();
            else
                hour = dt.Hour.ToString() + "";
            if (dt.Minute.ToString().Length < 2)
                minute = "0" + dt.Minute.ToString();
            else
                minute = dt.Minute.ToString() + "";
            if (dt.Second.ToString().Length < 2)
                second = "0" + dt.Minute.ToString();
            else
                second = dt.Minute.ToString() + "";
            dtnow = dt.Year.ToString() + month + day + hour + minute + second;
            return dtnow;
        }
        #endregion

        #region 生成验证码
        /// <summary>
        /// 生成验证码
        /// </summary>
        /// <param name="len">长度</param>
        /// <returns></returns>
        public  string ME_MakeRandom(int len)
        {
            Random rd = new Random();
            string str = "0123456789";
            string yzm = "";
            for (int i = 0; i < len; i++)
            {
                yzm += str[rd.Next(str.Length)];
            }
            return yzm;
        }
        #endregion
    }

    
}
